package com.itheima.api.treeset.demo08;

import java.util.Scanner;
import java.util.TreeSet;

public class TreeSetDemo01 {

    public static void main(String[] args) {

        TreeSet<Student> treeSet = new TreeSet<Student>((o1, o2) -> {

            int result = o2.getTotal() - o1.getTotal();
            int result2 = result == 0 ? o2.getChineseScore() - o1.getChineseScore() : result;
            int result3 = result2 == 0 ? o2.getMathScore() - o1.getMathScore() : result2;
            int result4 = result3 == 0 ? o2.getName().compareTo(o1.getName()) : result3;
            return result4;

        });

        for (int i = 0; i < 3; i++) {

            Scanner sc = new Scanner(System.in);
            System.out.println("请输入第" + (i+1) + "个学生的姓名：");
            String name = sc.next();

            System.out.println("请输入第" + (i+1) + "个学生的语文成绩：");
            String chineseScoreStr = sc.next();

            System.out.println("请输入第" + (i+1) + "个学生的数学成绩：");
            String mathScoreStr = sc.next();

            System.out.println("请输入第" + (i+1) + "个学生的英语成绩：");
            String englishScoreStr = sc.next();

            Student s = new Student();
            s.setName(name);
            s.setChineseScore(Integer.parseInt(chineseScoreStr));
            s.setMathScore(Integer.parseInt(mathScoreStr));
            s.setEnglishScore(Integer.parseInt(englishScoreStr));

            treeSet.add(s);

        }

        treeSet.forEach(s -> System.out.println(s.getName() + "----" + s.getTotal() + "----" + s.getChineseScore() + "----" + s.getMathScore() + "----" + s.getEnglishScore()));

    }

}
